<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Scratching Award</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    .container {
      width: 300px;
      height: 150px;
      position: relative;
      margin-left: 20px;
    }

    .mask {
      width: 100%;
      height: 100%;
      display: flex;
      flex-wrap: wrap;
      position: absolute;
      top: 0;
      left: 0;
    }

    .content {
      width: 100%;
      height: 100%;
      text-align: center;
      line-height: 150px;
      font-size: 30px;
      color: #fff;
      background-color: red;
    }
  </style>
</head>

<body>
  <div class="container">
    <div class="content"></div>
    <div class="mask">
    </div>
  </div>
  <script>
    const lotteryList = ['特等奖', '一等奖', '二等奖', '三等奖', '谢谢参与']
    let mask = document.querySelector('.mask');
    let content = document.querySelector('.content');
    window.onload = function () {
      initMask(10);
      watchTouch();
      getLotteryResult();
    }
    function getLotteryResult() {
      let result = lotteryList[Math.floor(Math.random() * lotteryList.length)]
      content.innerHTML = result;
    }
    function watchTouch() {
      let isTouch = false;
      mask.addEventListener('mousedown', function (e) {
        e.preventDefault();
        isTouch = true;
      })
      mask.addEventListener('mousemove', function (e) {
        e.preventDefault();
        if (isTouch) {
          e.target.style.opacity = '0';
        }
      });
      mask.addEventListener('mouseup', function (e) {
        e.preventDefault();
        isTouch = false;
      });
    }
    function initMask(count) {
      let maskWidth = mask.offsetWidth;
      let maskHeight = mask.offsetHeight;
      for (let i = 0; i < count * count; i++) {
        let div = document.createElement('div');
        div.style.width = `${maskWidth / count}px`;
        div.style.height = `${maskHeight / count}px`;
        div.style.backgroundColor = 'gray';
        mask.appendChild(div);
      }
    }
  </script>
</body>

</html>